home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / string / strncmp.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  604b  |  45 lines

  1.  
  2. /*
  3.  *  STRNCMP.C
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  7.  *    DICE-LICENSE.TXT.
  8.  */
  9.  
  10. #include <string.h>
  11.  
  12. #ifndef HYPER
  13. #define HYPER(x) x
  14. #endif
  15.  
  16. typedef unsigned char ubyte;
  17.  
  18. int
  19. HYPER(strncmp)(s, d, n)
  20. const char *s;
  21. const char *d;
  22. size_t n;
  23. {
  24.     char c;
  25.  
  26.     n;    /*  gets n into a register */
  27.     n;
  28.     d;
  29.     d;
  30.  
  31.     if (n == 0)
  32.     return(0);
  33.  
  34.     while ((c = *s) == *d) {
  35.     if (c == 0 || --n == 0)
  36.         return(0);
  37.     ++s;
  38.     ++d;
  39.     }
  40.     if ((ubyte)c < (ubyte)*d)
  41.     return(-1);
  42.     return(1);
  43. }
  44.  
  45.